home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 586 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  3.1 KB

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: clamage@Eng.sun.com (Steve Clamage)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: 'const' in header files
  5. Date: 28 Feb 1996 20:46:08 GMT
  6. Organization: Sun Microsystems Inc.
  7. Approved: clamage@eng.sun.com (comp.std.c++)
  8. Message-ID: <4h2bud$l69@engnews1.Eng.Sun.COM>
  9. References: <AD5A0C5196681CA0D@sleipner.nts.mh.se>
  10. Reply-To: clamage@Eng.sun.com
  11. NNTP-Posting-Host: taumet.eng.sun.com
  12. Content-Type: text
  13. X-Nntp-Posting-Host: taumet.eng.sun.com
  14. Content-Length: 2300
  15. X-Lines: 43
  16. Originator: clamage@taumet
  17.  
  18. In article AD5A0C5196681CA0D@sleipner.nts.mh.se, lars.farm@nts.mh.se (Lars Farm) writes:
  19. >This is a reply to a thread in c.l.c++.moderated. The moderator asked me to
  20. >post this in com.std.c++ instead. The thread started with someone
  21. >complaining about a warning for an unused variable where he had const float
  22. >x = y; in a header.
  23. >
  24. >Experts explained that this is as it should be for const float, but not for
  25. >const int (I know that the std does not talk about warnings). The point is:
  26. >The experts seems to find some kind of conceptual difference between named
  27. >constant floats and named constant ints, such that declaring const int K =
  28. >L; in a header is considered good practice but const float X = Y; in a
  29. >header is not and justifies a warning. I don't think there should be any
  30. >such difference.
  31.  
  32. I was one of the people who posted articles on that thread, and I
  33. certainly never said there was or should be any conceptual difference.
  34. I did say the compiler is allowed to treat them differently.
  35.  
  36. AS AN OPTIMIZATION, a non-extern const does not always need to be
  37. instantiated.  No compiler is required to make that optimization, to
  38. document whether it makes that optimization, or even to be consistent
  39. about such optimizations.  That is the whole point of optimizations:
  40. no portable and standard-conforming program can tell the difference.
  41. You have to resort to things like examining the executable image, or
  42. performing a timing analysis, or some other technique outside the
  43. language definition.
  44.  
  45. Why do I say this is an optimization? The standard doesn't (and
  46. shouldn't, in my view) say explicitly that it is sometimes ok to omit
  47. the instantiation.  Instead, it says what the results of certain
  48. operations must be. It turns out that no valid program can detect
  49. that a const was omitted. Any valid test the program makes will report
  50. that the constant was instantiated.  The compiler can choose to omit
  51. the instantiation only if you don't try to find out that it did.
  52. (Shroedinger, anyone?)
  53.  
  54. If you are unhappy about your compiler generating unncessary code or
  55. data, or warning about things which you think are the compiler's own
  56. fault, you should take that up with the vendor. In this particular
  57. case, no language rule is being violated.
  58.  
  59. ---
  60. Steve Clamage, stephen.clamage@eng.sun.com
  61.  
  62.  
  63.  
  64.  
  65. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your
  66.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  67.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  68.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  69.   Comments? mailto:std-c++-request@ncar.ucar.edu
  70. ]
  71.